<?php
/*
 * Filter voor reistype
 */
$this->load->helper('form');
?>
<h3>Zoek uw reis</h3>
<?php
echo form_open('reis/page');
?>
<p>Zoeken:</p>
<?php
echo form_input('reisfilter[zoek]', '', 'id ="zoekterm"');


if (isset($reistype)) {
    ?>
    <p>Reistype:</p>
    <?php
    echo form_dropdown('reisfilter[reistype]', $reistype, (isset($selected['reistype']) ? $selected['reistype'] : null), 'id="reistype"');
    ?>

    <?php
}
if (isset($continenten)) {
    ?>
    <p>Continent:</p>
    <?php
    echo form_dropdown('reisfilter[continent]', $continenten, (isset($selected['continent']) ? $selected['continent'] : null), 'id="continent"');
    ?>

    <?php
}
if (isset($landen)) {
    ?>
    <p>Land:</p>
    <?php
    echo form_dropdown('reisfilter[land]', $landen, (isset($selected['land']) ? $selected['land'] : null), 'id="landen"');
    ?>

    <?php
}
?>
<br />
<?php
echo form_submit('submit', 'Filter', 'id="submit"');
?>
<?php
echo form_close();
?>

<script type="text/javascript">
$('#submit').click(function(e){
    e.preventDefault();//Voorkomen dat de standaard klik actie uitgevoerd word.
    setFilters();
    return false;

});
    
$('#zoekterm').keyup(function() {
    delay(function(){
      setFilters();
    }, 200 );
});

$('#reistype, #landen, #continent').change(function(){
    setFilters();
});

function setFilters(){
    var form_data = {};
    form_data['reisfilter'] = { 
        'zoek' : $('#zoekterm').val(),
        'reistype':$('#reistype').val(),
        'continent':$('#continent').val(),
        'land':$('#landen').val()
    };
    form_data['ajax'] = 1;


    $.ajax({
        url:  "<?php echo site_url('reis/page'); ?>",
        type: 'POST',
        data: form_data,
        success: function(msg){
            $('#main').html(msg);              
        },
        error: function(msg){
            console.log(msg);
        }

    });
}

var delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();
</script>